<template>
  <!-- 添加或修改盘点计划对话框 -->
  <el-dialog :title="title" v-if="open" v-model="open" width="550px" append-to-body>

    <el-form ref="form" :model="form" :rules="rules" label-width="130px">

      <el-form-item label="分组名称:" prop="id">
        <el-select v-model="form.id" value-key="" placeholder="" clearable filterable>
          <el-option v-for="item in fodders" :key="item.id" :label="item.groupName" :value="item.id">
          </el-option>
        </el-select>

      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import modelMixin from '@/mixins/modelMixin'
import materialPptGroup from '@/api/goods/materialPptGroup/index';
import { listMaterialPptGroup } from '@/api/goods/materialPptGroup/index'
export default {
  name: "addForm",
  mixins: [modelMixin],
  props: {
    classifyList: {
      type: Array,
      default: () => []
    },
  },
  data() {
    return {
      funcObj: materialPptGroup,//方法对象
      open: false,
      title: "删除分组",
      form: {},
      fodders: [],
      rules: {
        id: [
          { required: true, message: "请选择分组", trigger: "blur" }
        ]
      },
      // classifyList: [],
    }
  },
  created() {
    // this.getClassifyAllList()
  },
  methods: {
    show(row) {
      this.open = true;
      this.getGroupList()
      this.form = row || {}
      this.title = "删除分组"
    },
    classifyForm() {
      this.form.groupStatus = 0
    },

    getGroupList() {
      listMaterialPptGroup().then(res => {
        if (res.code == 200) {
          this.fodders = res.rows
        } else {
          this.$modal.msgError(res.msg)
        }
      }).catch(err => {
        console.log('err :>> ', err);
      })
    },
    submitForm() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$modal.confirm('是否删除该分组?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.funcObj.del(this.form.id).then(res => {
              if (res.code == 200) {
                this.$modal.msgSuccess(res.msg)
                this.open = false
                this.$emit('ok')
              } else {
                this.$modal.msgError(res.msg)
              }
            }).catch(err => {
              console.log('err :>> ', err);
            })
          }).catch((err) => {
            console.log('err :>> ', err);
            this.$modal.msgError('删除异常')
          });
        }
      })
    }
  }
}
</script>

<style lang="scss">
.el-form-item__content {
  width: auto !important;
}
</style>